/**
    入驻小区
**/
(function(vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            partnerLogInfo: {
                partnerLogs: [],
                partners:[],
                total: 0,
                records: 1,
                moreCondition: false,
                logId: '',
                conditions: {
                    ppId: '',
                    logAction: '',
                    state: '',
                    userName: '',
                    queryStartTime:'',
                    queryEndTime:''
                }
            }
        },
        _initMethod: function() {
            $that._listPartners();
            vc.initDateTime('queryStartTime',function(_value){
                $that.partnerLogInfo.conditions.queryStartTime = _value;
            });
            vc.initDateTime('queryEndTime',function(_value){
                $that.partnerLogInfo.conditions.queryEndTime = _value;
            });
        },
        _initEvent: function() {

            vc.on('partnerLog', 'listPartnerLog', function(_param) {
                $that._listPartnerLogs(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function(_currentPage) {
                $that._listPartnerLogs(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listPartnerLogs: function(_page, _rows) {

                $that.partnerLogInfo.conditions.page = _page;
                $that.partnerLogInfo.conditions.row = _rows;
                $that.partnerLogInfo.conditions.shopId = vc.getCurrentCommunity().shopId;
                let param = {
                    params: $that.partnerLogInfo.conditions
                };

                //发送get请求
                vc.http.apiGet('/partner.listPartnerLog',
                    param,
                    function(json, res) {
                        let _json = JSON.parse(json);
                        $that.partnerLogInfo.total = _json.total;
                        $that.partnerLogInfo.records = _json.records;
                        $that.partnerLogInfo.partnerLogs = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.partnerLogInfo.records,
                            currentPage: _page,
                            dataCount:_json.total
                        });
                    },
                    function(errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openViewPartnerLogModel: function(_log) {
                vc.emit('showPartnerLog', 'openShowPartnerLogModal', _log);
            },

            _queryPartnerLogMethod: function() {
                $that._listPartnerLogs(DEFAULT_PAGE, DEFAULT_ROWS);

            },
            _listPartners: function(_page, _rows) {

                let param = {
                    params: {
                        page:1,
                        row:100,
                        shopId:vc.getCurrentCommunity().shopId
                    }
                };

                //发送get请求
                vc.http.apiGet('/partner.listPartnerPool',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.partnerLogInfo.partners = _json.data;
                        if(_json.data && _json.data.length >0){
                            $that.partnerLogInfo.conditions.ppId = _json.data[0].ppId;
                            $that._listPartnerLogs(DEFAULT_PAGE, DEFAULT_ROWS);
                        }
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            swatchPartner: function(_partner) {
                $that.partnerLogInfo.conditions.machineId = _partner.machineId;
                $that._listPartnerLogs(DEFAULT_PAGE, DEFAULT_ROWS);
            },


        }
    });
})(window.vc);